package com.cloud.rou.im.protocol.serialize;


import com.alibaba.fastjson.JSON;
import com.cloud.rou.im.core.util.ObjectNullUtil;
import com.cloud.rou.im.core.util.SingletonUtil;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 */
@BindAndEnableSerializer(name = SerializeTypeConstants.FAST_JSON)
public class FastJsonSerializer implements Serializer {

    private FastJsonSerializer() {

    }
    public static FastJsonSerializer getInstance(){
        return SingletonUtil.get(FastJsonSerializer.class);
    }

    @Override
    public byte[] serialize(Object object) {
        ObjectNullUtil.notNull(object);
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) {
        ObjectNullUtil.notNull(bytes);
        return JSON.parseObject(bytes, clazz);
    }

}
